﻿/*
 * KLF Headless Browser
 * Written by Kris Oye <kristianoye@gmail.com>
 * Copyright (C) 2011-2012.  All rights reserved.
 */
namespace KLF.Lib.Browser.DOM
{
    #region Using Statements

    using System;

    #endregion

    public class DOMException : Exception
    {
        public const short INDEX_SIZE_ERR = 1;
        public const short DOMSTRING_SIZE_ERR = 2;
        public const short HIERARCHY_REQUEST_ERR = 3;
        public const short WRONG_DOCUMENT_ERR = 4;
        public const short INVALID_CHARACTER_ERR = 5;
        public const short NO_DATA_ALLOWED_ERR = 6;
        public const short NO_MODIFICATION_ALLOWED_ERR = 7;
        public const short NOT_FOUND_ERR = 8;
        public const short NOT_SUPPORTED_ERR = 9;
        public const short INUSE_ATTRIBUTE_ERR = 10;

        // Introduced in DOM Level 2:
        public const short INVALID_STATE_ERR = 11;
        // Introduced in DOM Level 2:
        public const short SYNTAX_ERR = 12;
        // Introduced in DOM Level 2:
        public const short INVALID_MODIFICATION_ERR = 13;
        // Introduced in DOM Level 2:
        public const short NAMESPACE_ERR = 14;
        // Introduced in DOM Level 2:
        public const short INVALID_ACCESS_ERR = 15;

        // Introduced in DOM Level 3:
        public const short VALIDATION_ERR = 16;
        // Introduced in DOM Level 3:
        public const short TYPE_MISMATCH_ERR = 17;

        protected static string CodeLookup(short code)
        {
            switch (code)
            {
                case INDEX_SIZE_ERR: return "INDEX_SIZE_ERR";
                case DOMSTRING_SIZE_ERR: return "DOMSTRING_SIZE_ERR";
                case HIERARCHY_REQUEST_ERR: return "HIERARCHY_REQUEST_ERR";
                case WRONG_DOCUMENT_ERR: return "WRONG_DOCUMENT_ERR";
                case INVALID_CHARACTER_ERR: return "INVALID_CHARACTER_ERR";
                case NO_DATA_ALLOWED_ERR: return "NO_DATA_ALLOWED_ERR";
                case NO_MODIFICATION_ALLOWED_ERR: return "NO_MODIFICATION_ALLOWED_ERR";
                case NOT_FOUND_ERR: return "NOT_FOUND_ERR";
                case NOT_SUPPORTED_ERR: return "NOT_SUPPORTED_ERR";
                case INUSE_ATTRIBUTE_ERR: return "INUSE_ATTRIBUTE_ERR";
                case INVALID_STATE_ERR: return "INVALID_STATE_ERR";
                case SYNTAX_ERR: return "SYNTAX_ERR";
                case INVALID_MODIFICATION_ERR: return "INVALID_MODIFICATION_ERR";
                case NAMESPACE_ERR: return "NAMESPACE_ERR";
                case INVALID_ACCESS_ERR: return "INVALID_ACCESS_ERR";
                case VALIDATION_ERR: return "VALIDATION_ERR";
                case TYPE_MISMATCH_ERR: return "TYPE_MISMATCH_ERR";
                default: return "DOM_UNKNOWN_ERROR";
            }
        }

        public DOMException(short code)
            : base(DOMException.CodeLookup(code))
        {
        }

        public DOMException(short code, Exception innerException)
            : base(DOMException.CodeLookup(code), innerException)
        {
        }
    }
}
